package com.hwua.view;

import com.hwua.domain.Car;
import com.hwua.service.CarService;
import com.hwua.serviceimpl.CarServiceImpl;
import com.hwua.util.InputTools;

import java.util.List;

/**
 * 通过汽车id修改汽车信息界面
 * @author admin
 */
public class AlterCarByCarIdView extends AbstractView{
    private int num2;
    public AlterCarByCarIdView(int num2){
        this.num2=num2;
    }
    private String rentStatus;
    private String putAwayStatus;
    @Override
    public AbstractView showView() {
        CarService cs = new CarServiceImpl();
        List<Car> carList = cs.findCarById(num2, "汽车id");
        System.out.println("================================================<<指定汽车编号修改汽车>>============================================");
        System.out.println("编号\t汽车名称\t\t备注\t\t\t品牌\t\t类型\t\t颜色\t\t日租金\t\t是否可租\t\t是否上架");
        for (Car car : carList) {
            if(car.getRentStatus()==0){
                rentStatus="可租";
            }else{
                rentStatus="不可租";
            }
            if(car.getPutAwayStatus()==0){
                putAwayStatus="上架";
            }else{
                putAwayStatus="下架";
            }
            System.out.println(car.getCarId()+"\t\t"+car.getCarName()+"\t\t\t"+car.getCarRemark()+"\t\t"+ car.getBrand()
                    +"\t\t"+car.getType()+"\t\t"+car.getColor()+"\t\t"+car.getDailyRent()+"\t\t"+rentStatus+"\t\t\t"+putAwayStatus);
        }
        System.out.println("---------------------------------------------------------------------------------");
        System.out.println("请输入要修改的内容编号(1.租赁价格   2.上架下架):");
        int input = InputTools.checkIntInput(1, 2);
        switch (input){
            case 1:
                System.out.println("请输入新的租赁价格：");
                double dailyRent = InputTools.checkDoubleInput(0, 1000000);
                List<Car> list = cs.alterDailyRentById(num2, dailyRent);
                if(!list.isEmpty()){
                    System.out.println("修改成功！");
                    System.out.println("===============================================================================================");
                    System.out.println("编号\t汽车名称\t\t备注\t\t\t品牌\t\t类型\t\t颜色\t\t日租金\t\t是否可租\t\t是否上架");
                    for (Car car : list) {
                        if(car.getRentStatus()==0){
                            rentStatus="可租";
                        }else{
                            rentStatus="不可租";
                        }
                        if(car.getPutAwayStatus()==0){
                            putAwayStatus="上架";
                        }else{
                            putAwayStatus="下架";
                        }
                        System.out.println(car.getCarId()+"\t\t"+car.getCarName()+"\t\t\t"+car.getCarRemark()+"\t\t"+ car.getBrand()
                                +"\t\t"+car.getType()+"\t\t"+car.getColor()+"\t\t"+car.getDailyRent()+"\t\t"+rentStatus+"\t\t\t"+putAwayStatus);
                    }
                    nextView = new AdminView();
                }else{
                    System.out.println("修改失败，请重新修改！");
                    nextView = new AlterCarByCarIdView(num2);
                }
                break;
            case 2:
                System.out.println("请选择上架状态（0:上架  1:下架）：");
                int i = InputTools.checkIntInput(0, 1);
                List<Car> list1 = cs.alterPutAwayStatusById(num2, i);
                if(!list1.isEmpty()){
                    System.out.println("修改成功！");
                    System.out.println("===============================================================================================");
                    System.out.println("编号\t汽车名称\t\t备注\t\t\t品牌\t\t类型\t\t颜色\t\t日租金\t\t是否可租\t\t是否上架");
                    for (Car car : list1) {
                        if(car.getRentStatus()==0){
                            rentStatus="可租";
                        }else{
                            rentStatus="不可租";
                        }
                        if(car.getPutAwayStatus()==0){
                            putAwayStatus="上架";
                        }else{
                            putAwayStatus="下架";
                        }
                        System.out.println(car.getCarId()+"\t\t"+car.getCarName()+"\t\t\t"+car.getCarRemark()+"\t\t"+ car.getBrand()
                                +"\t\t"+car.getType()+"\t\t"+car.getColor()+"\t\t"+car.getDailyRent()+"\t\t"+rentStatus+"\t\t\t"+putAwayStatus);
                    }
                    nextView = new AdminView();
                }else{
                    System.out.println("修改失败，请重新修改！");
                    nextView = new AlterCarByCarIdView(num2);
                }
                break;
            default:break;
        }

        return nextView;
    }
}
